package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	users "users_demo/service"
)

func getUser(client users.UsersClient, u *users.UserGetRequest) (*users.UserGetReply, error) {
	return client.GetUser(context.Background(), u)
}

func main() {
	conn, err := grpc.DialContext(
		context.Background(),
		"127.0.0.1:3001",
		grpc.WithInsecure(),
		grpc.WithBlock(),
	)
	if err != nil {
		fmt.Println("连接客户端失败", err)
		return
	}
	defer func(conn *grpc.ClientConn) {
		err := conn.Close()
		if err != nil {
			fmt.Println("关闭客户端失败", err)
		}
	}(conn)

	//c := users.NewUsersClient(context.Background(), users.UserGetRequest{})

	c := users.NewUsersClient(conn)
	result, err := getUser(c, &users.UserGetRequest{
		Email: "hello@qq.com",
		Id:    5,
	})
	if err != nil {
		fmt.Println("getUSer失败", err)
		return
	}
	fmt.Println("显示收到的数据信息", result.User.Id, result.User.LastName)
	fmt.Println("显示收到的数据信息", result)
}
